package forces;

import java.util.Collection;
import java.util.Scanner;
import simulation.Mass;


/**
 * This class represents a Gravity force on masses.
 * 
 * 
 */
public class Gravity extends Force {
    private static final double DEFAULT_ANGLE = 90;
    private static final double DEFAULT_MAGNITUDE = 1;
    private double myAcceleration;

    /**
     * A default constructor that specifies the direction and magnitude of
     * gravitational acceleration.
     */
    public Gravity () {
        this(DEFAULT_ANGLE, DEFAULT_MAGNITUDE);
    }

    /**
     * Creates a gravity force with the specified direction and magnitude of
     * acceleration.
     */
    public Gravity (double angle, double magnitude) {
        super(angle, magnitude);
        myAcceleration = magnitude;
    }

    public Gravity (Scanner line) {
        this(line.nextDouble(), line.nextDouble());
    }

    /**
     * Implements the abstract update method to calculate and apply
     * the gravitational force on each mass.
     */
    @Override
    public void update (Collection<Mass> masses) {
        for (Mass m : masses) {
            setMagnitude(m.getMass() * myAcceleration);
            m.applyForce(this);
        }
    }

}
